<template>
	<view>
		<view class="clientSearchItem02">
			<button class="searchBt" @tap="Clear()" style="">清空</button>
			<button class="searchBt" @tap="UploadFile()">保存</button>
		</view>
		<view class="detail-box">
			<view class="cu-form-group02">
			   <view class="grid col-4 grid-square flex-sub">
			    <view class="bg-img" v-for="(item,index) in imgList" :key="index" @tap="chooseImage" :data-url="item.imgUrl">
			     <image :src="item.imgUrl" mode="aspectFill" ></image>
			     <view class="cu-tag bg-red" @tap.stop="DelImg" :data-index="index">
			      <text class='cuIcon-close'></text>
			     </view>
			    </view>
			    <view class="solids" @tap="chooseImage" v-if="imgList.length<1">
			     <text class='cuIcon-cameraadd'></text>
			    </view>
			   </view>
			  </view>
			<!-- 上传图片的 -->
			<!-- <view class="cu-form-group2">
				<button @tap="chooseImage">选择图片</button>
				<image :src="loadImg" style="width: 100px;height:100px"></image>
			</view> -->
			<view class="cu-form-group">
				<view class="title">主条码：</view>
				<input class="inpt" name="input" placeholder="输入条码" v-model="NowSelectGoods.BarCode" ></input>
				<!-- <button class="cu-btn round stop text-white" @tap="gogoodlist">查询</button> -->
			</view>
			<view class="cu-form-group">
				<view class="title">商品编号：</view>
				<input class="inpt" name="input" placeholder="输入编号" v-model="NowSelectGoods.GoodsCode"></input>
				<!-- <button class="cu-btn round stop text-white" @tap="gogoodlist">查询</button> -->
			</view>
			<view class="cu-form-group">
				<view class="title">商品名称：</view>
				<input class="inpt" name="input" placeholder="输入名称" v-model="NowSelectGoods.GoodsName"></input>
				<!-- <button class="cu-btn round stop text-white" @tap="gogoodlist">查询</button> -->
			</view>
			<view class="cu-form-group">
				<view class="title">规格：</view>
				<input class="inpt" name="input" placeholder="请输入规格" v-model="Spec"></input>
				<!-- <button class="cu-btn round stop text-white" @tap="gogoodlist">查询</button> -->
			</view>
			<view class="cu-form-group">
				<view class="title">基本单位：</view>
				<picker @change="PickerChange2" :value="index2" :range="picker2">
					<view class="picker">
						{{index2>-1?picker2[index2]:''}}
					</view>
				</picker>
			</view>
			<view class="cu-form-group">
				<view class="title">商品类型：</view>
				<picker @change="PickerChange3" :value="index3" :range="picker3">
					<view class="picker">
						{{index3>-1?picker3[index3]:''}}
					</view>
				</picker>
			</view>
			<view class="cu-form-group">
				<view class="title">*供&nbsp;应&nbsp;商&nbsp;:</view>
				<input class="inpt" name="input" placeholder="点击获取" :value="SelectClientObj.ClientName" disabled @tap="AddClientListen()"></input>
				<!-- <view class="inpt1"><input type="text" placeholder="点击获取" :value="SelectClientObj.ClientName" disabled="true" style="text-align: left;"
					 @tap="AddClientListen()" /></view> -->
			</view>
			<view class="cu-form-group" @tap="goInitial">
				<view class="title">期初库存--点击（期初库存）</view>
				<!-- <input class="inpt" name="input" disabled="true" :value="NowSelectGoods.stockqty"></input> -->
			</view>
			<view class="cu-form-group">
				<view class="title">进价：</view>
				<input class="inpt" name="input" placeholder="" v-model="NowSelectGoods.InPrice"  type="number"></input>
				<!-- <button class="cu-btn round stop text-white" @tap="gogoodlist">查询</button> -->
			</view>
			<view class="cu-form-group">
				<view class="title">零售价：</view>
				<input class="inpt" name="input" placeholder="" v-model="NowSelectGoods.SalePrice" type="number"></input>
				<!-- <button class="cu-btn round stop text-white" @tap="gogoodlist">查询</button> -->
			</view>
			<view class="cu-form-group">
				<view class="title">单价1：</view>
				<input class="inpt" name="input" placeholder="" v-model="NowSelectGoods.Price1" type="number"></input>
				<!-- <button class="cu-btn round stop text-white" @tap="gogoodlist">查询</button> -->
			</view>
			<view class="cu-form-group">
				<view class="title">单价2：</view>
				<input class="inpt" name="input" placeholder="" v-model="NowSelectGoods.Price2" type="number"></input>
				<!-- <button class="cu-btn round stop text-white" @tap="gogoodlist">查询</button> -->
			</view>
			<view class="cu-form-group">
				<view class="title">配送价：</view>
				<input class="inpt" name="input" placeholder="" v-model="NowSelectGoods.Price3" type="number"></input>
				<!-- <button class="cu-btn round stop text-white" @tap="gogoodlist">查询</button> -->
			</view>
			<view class="cu-form-group">
				<view class="title">会员价：</view>
				<input class="inpt" name="input" placeholder="" v-model="NowSelectGoods.VipPrice" type="number"></input>
				<!-- <button class="cu-btn round stop text-white" @tap="gogoodlist">查询</button> -->
			</view>
			<view class="cu-form-group">
				<view class="title">批发价：</view>
				<input class="inpt" name="input" placeholder="" v-model="NowSelectGoods.PFPrice" type="number"></input>
				<!-- <button class="cu-btn round stop text-white" @tap="gogoodlist">查询</button> -->
			</view>
			<view class="cu-form-group">
				<view class="title">备注：</view>
				<input class="inpt" name="input" placeholder="" v-model="NowSelectGoods.Remark"></input>
				<!-- <button class="cu-btn round stop text-white" @tap="gogoodlist">查询</button> -->
			</view>
			<view class="cu-form-group">
				<view class="title">*停止进货</view>
				<input class="inpt" :value="NowSelectGoods.IsStopIn+''=='true'?'是':'否'" @tap="OpModal" :data-type="3" disabled=""></input>
				<view class="cu-modal" :class="showOpmodle?'show':'hide'">
					<view class="cu-dialog">
						<view class="cu-bar bg-white justify-end">
							<view class="cuIcon-home content">是否停止进货</view>
							<view class="action" @tap="hideModal(3)">
								<text class="cuIcon-close text-blue"></text>
							</view>
						</view>
						<radio-group class="block" @change="OpChangeStop">
							<view class="cu-list menu text-left">
								<view class="cu-item" v-for="(item,index) in IsStopGetGoodList" :key="index">
									<label class="flex justify-between align-center flex-sub">
										<view class="title1">{{item.Name}}</view>
										<radio class="round" :class="NowSelectGoods.IsStopIn+''==item.type?'checked':''" :checked="NowSelectGoods.IsStopIn+''==item.type?true:false" :value="item.type+''"></radio>
										<!-- <jiuaiCheckbox @change='changeBox' :value="item.value" :checked="item.checked"></jiuaiCheckbox> -->
									</label>
								</view>
							</view>
						</radio-group>
					</view>
				</view>
			</view>
			<view class="cu-form-group">
				<view class="title">*停止销售</view>
				<input class="inpt" :value="NowSelectGoods.IsStopSale+''=='true'?'是':'否'" @tap="OpModal" :data-type="2" disabled=""></input>
				<view class="cu-modal" :class="showStopSale?'show':'hide'">
					<view class="cu-dialog">
						<view class="cu-bar bg-white justify-end">
							<view class="cuIcon-home content">是否停止销售</view>
							<view class="action" @tap="hideModal(2)">
								<text class="cuIcon-close text-blue"></text>
							</view>
						</view>
						<radio-group class="block" @change="OpChangeSalc">
							<view class="cu-list menu text-left">
								<view class="cu-item" v-for="(item,index) in IsStopGetGoodList" :key="index">
									<label class="flex justify-between align-center flex-sub">
										<view class="title1">{{item.Name}}</view>
										<radio class="round" :class="NowSelectGoods.IsStopSale+''==item.type?'checked':''" :checked="NowSelectGoods.IsStopSale+''==item.type?true:false" :value="item.type+''"></radio>
										<!-- <jiuaiCheckbox @change='changeBox' :value="item.value" :checked="item.checked"></jiuaiCheckbox> -->
									</label>
								</view>
							</view>
						</radio-group>
					</view>
				</view>
			</view>
			<view class="cu-form-group">
				<view class="title">*停止使用</view>
				<input class="inpt" :value="NowSelectGoods.IsStop+''=='true'?'是':'否'" @tap="OpModal" :data-type="1" disabled=""></input>
				<view class="cu-modal" :class="showUserModal?'show':'hide'">
					<view class="cu-dialog">
						<view class="cu-bar bg-white justify-end">
							<view class="cuIcon-home content">是否停止使用</view>
							<view class="action" @tap="hideModal(1)">
								<text class="cuIcon-close text-blue"></text>
							</view>
						</view>
						<radio-group class="block" @change="OpChangeUser">
							<view class="cu-list menu text-left">
								<view class="cu-item" v-for="(item,index) in IsStopUserList" :key="index">
									<label class="flex justify-between align-center flex-sub">
										<view class="title1">{{item.Name}}</view>
										<radio class="round" :class="NowSelectGoods.IsStop+''==item.type?'checked':''" :checked="NowSelectGoods.IsStop+''==item.type?true:false" :value="item.type+''"></radio>
									</label>
								</view>
							</view>
						</radio-group>
					</view>
				</view>
			</view>
			<view class="cu-form-group">
				<view class="title">*批号管理</view>
				<input class="inpt" :value="NowSelectGoods.IsBatch+''=='true'?'是':'否'" @tap="OpModal" :data-type="4" disabled=""></input>
				<view class="cu-modal" :class="showStopInv?'show':'hide'">
					<view class="cu-dialog">
						<view class="cu-bar bg-white justify-end">
							<view class="cuIcon-home content">是否批号管理</view>
							<view class="action" @tap="hideModal(4)">
								<text class="cuIcon-close text-blue"></text>
							</view>
						</view>
						<radio-group class="block" @change="OpChangeInv">
							<view class="cu-list menu text-left">
								<view class="cu-item" v-for="(item,index) in IsStopInvList" :key="index">
									<label class="flex justify-between align-center flex-sub">
										<view class="title1">{{item.Name}}</view>
										<radio class="round" :class="NowSelectGoods.IsBatch+''==item.type?'checked':''" :checked="NowSelectGoods.IsBatch+''==item.type?true:false" :value="item.type+''"></radio>
									</label>
								</view>
							</view>
						</radio-group>
					</view>
				</view>
			</view>
			<view class="cu-form-group">
				<view class="title">保质天数：</view>
				<input class="inpt" name="input" placeholder="" v-model="NowSelectGoods.Days"></input>
				<!-- <button class="cu-btn round stop text-white" @tap="gogoodlist">查询</button> -->
			</view>
			<view class="cu-form-group" @tap="goBarCode" v-show="type==0">
				<view class="title">设置多条码</view>
				<input class="inpt" name="input" disabled="true"></input>
			</view>

			<view class="cu-form-group" @tap="addMoreUnit" v-show="type==0">
				<view class="title">设置多单位</view>
				<input class="inpt" name="input" disabled="true" ></input>
			</view>
		</view>
	</view>
</template>

<script>
	import * as Api from '@/syApis/syDa/syDa.js';
	import jiuaiCheckbox from "@/components/jiuai-checkbox.vue";
	import defaultValue from '@/Json.js'
	export default {
		data() {
			return {
				//选择的商品
				NowSelectGoods: {
					BarCode:"",
					GoodsCode:"",
					GoodsName:"",
					Spec:"",
					InPrice:0,
					SalePrice:0,
					Price1:0,
					Price2:0,
					Price3:0,
					VipPrice:0,
					PFPrice:0,
					Remark:"",
					IsStopIn:false,
					IsStopSale:false,
					IsStop:false,
					IsBatch:false,
					Days:0
					
				},
				//添加的备注
				GoodsRemark: "",
				//商品库存
				GoodsStorm: 0,
				//商品税率
				Tax: 0,
				//商品
				GoodsQty: 0,
				//商品折扣
				GoodsDiscount: "",
				//主要供应商ID
				ClientID: "",
				//单位ID
				UnitID: "",
				//商品类型ID
				GoodsTypeID: "",
				//当前商品在原商品数组对应的位置
				index2: 0,
				picker2: [],
				index3: 0,
				picker3: [],
				index4: 0,
				picker4: [],
				SelectStockNum: "",
				StoreList: [],
				treatmentStatu: {
					checked: false
				},
				PHtreatmentStatu: {
					checked: false
				},
				CGtreatmentStatu: {
					checked: false
				},
				XStreatmentStatu: {
					checked: false
				},
				//商品明细
				goodinfo: {},
				//新增或是修改
				type: 0,
				//当前选择的供应商或者客户条目
				SelectClientObj: {
					ClientName: "",
					CreateID: ""
				},

				ClientTitle: "供应商",
				//是否停止进货弹框
				showOpmodle: false,
				//是否停止进货
				IsStopGetGoodList: [{
						Name: "否",
						type:"false"
					},
					{
						Name: "是",
						type:"true"
					}
				],
				//是否停止销售
				IsStopSalcList: [{
						Name: "否",
						type:"false"
					},
					{
						Name: "是",
						type:"true"
					}
				],
				//是否停止使用
				IsStopUserList: [{
						Name: "否",
						type:"false"
					},
					{
						Name: "是",
						type:"true"
					}
				],
				//是否停止使用
				IsStopInvList: [{
						Name: "否",
						type:"false"
					},
					{
						Name: "是",
						type:"true"
					}
				],
				radio: "",
				//是否停止销售弹框
				showStopSale: false,
				showUserModal: false,
				showStopInv: false,
				//是否停止进货
				IsStopSalcGood: "否",
				IsStopGetGood: "否",
				IsStopInvGood: "否",
				IsStopUser: "否",
				//存放图片的
				imgList: [],
				loadImg:"",
				//图片地址
				Goods_Image_Path1:"",
				GoodTypeList:[],
				UnitList:[],
				Spec:"",
				//上传的本地图片路径
				uploadDef:""

			}
		},
		components: {
			jiuaiCheckbox
		},
		created() {
			
			// this.Get_ClientMessage(); //供应商下拉框
		},
		onLoad(options) {
			this.ClientTitle = options.BillName == '采购订单' ? "供应商" : "客户";
			console.log(options);
			//采购订单
			this.type = options.type;
			if (options.type == 0) {
				this.OrderTitle = "修改商品档案";
				this.NowSelectGoods = JSON.parse(options.goodInfo);
				console.log(JSON.parse(options.goodInfo));
				console.log(this.NowSelectGoods);
				this.SelectClientObj.ClientID = this.NowSelectGoods.ClientID;
				this.SelectClientObj.ClientName = this.NowSelectGoods.ClientName;
				this.Spec = this.NowSelectGoods.Spec;
				this.IsStopInvGood = this.NowSelectGoods.IsBatch;
				this.IsStopUser = this.NowSelectGoods.IsStop ;
				this.IsStopSalcGood = this.NowSelectGoods.IsStopSale;
				this.IsStopGetGood = this.NowSelectGoods.IsStopIn;
				// this.
				console.log(defaultValue.imgurlHeader);
                if(this.NowSelectGoods.Goods_Image_Path1 != "" && typeof this.NowSelectGoods.Goods_Image_Path1 == 'string'){
					   this.Goods_Image_Path1 = this.NowSelectGoods.Goods_Image_Path1;
				       this.NowSelectGoods.Goods_Image_Path1 = defaultValue.imgurlHeader+this.NowSelectGoods.Goods_Image_Path1;
						let item = {imgUrl:this.NowSelectGoods.Goods_Image_Path1};
						
						this.imgList.push(item);
				}else{
					
				}
				console.log(this.goodinfo);
				// this.isSupperPurb = true;
			}
			//销售订单
			else {
				
				this.OrderTitle = "新增商品档案";
				// this.NowSelectGoods = {
				// 	BarCode:"",
				// 	GoodsCode:"",
				// 	GoodsName:"",
				// 	Spec:"",
				// 	stockqty:"",
				// 	InPrice:"0",
				// 	SalePrice:"0",
				// 	Price1:"0",
				// 	Price2:"0",
				// 	Price3:"0",
				// 	VipPrice:"0",
				// 	InPrice:"0",
				// 	SalePrice:"0",
				// 	PFPrice:"0",
				// 	Remark:"0",
				// 	Days:"0"
				// }
				// this.NowSelectGoods.BarCode = "";
				// this.NowSelectGoods.GoodsCode = "";
				// this.NowSelectGoods.GoodsName = "";XZ  
				// this.NowSelectGoods.Spec = "";
				// this.NowSelectGoods.stockqty = "";
				// this.NowSelectGoods.InPrice = "0";
				// this.NowSelectGoods.SalePrice = "0";
				// this.NowSelectGoods.Price1 = "0";
				// this.NowSelectGoods.Price2 = "0";
				// this.NowSelectGoods.Price3 = "0";
				// this.NowSelectGoods.VipPrice = "0";
				// this.NowSelectGoods.InPrice = "0";
				// this.NowSelectGoods.SalePrice = "0";
				// this.NowSelectGoods.PFPrice = "0";
				// this.NowSelectGoods.Remark = "";
				// this.NowSelectGoods.Days = "";
				// this.isSupperPurb = false;
				// this.NowSelectGoods.BarCode = "";
				// this.NowSelectGoods.GoodsCode = "";
				// this.NowSelectGoods.GoodsName = "";
				// // this.NowSelectGoods.Spec = "";
				// this.NowSelectGoods.stockqty = "";
				// this.NowSelectGoods.InPrice = "0";
				// this.NowSelectGoods.SalePrice = "0";
				// this.NowSelectGoods.Price1 = "0";
				// this.NowSelectGoods.Price2 = "0";
				// this.NowSelectGoods.Price3 = "0";
				// this.NowSelectGoods.VipPrice = "0";
				// this.NowSelectGoods.PFPrice = "0";
				// this.NowSelectGoods.Remark = "";
				// this.NowSelectGoods.Days = "";
			}
			uni.setNavigationBarTitle({
				title: this.OrderTitle
			})
			this.Get_GoodsUnitMessage(); //商品单位下拉框
			this.GoodsTypeList(); //商品类型下拉框
		},
		mounted() {
		
		},
		methods: {
			//选择图片
			chooseImage() {
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					// sourceType: ['camera'], //从相册选择
					success: (chooseImageRes) => {
						this.imgList = [];
						const tempFilePaths = chooseImageRes.tempFilePaths;
						let item = {imgUrl:tempFilePaths[0]};
						this.imgList.push(item);
						console.log(tempFilePaths[0]);
					}
				});
			},
			//上传图片
			UploadFile(){
				uni.showLoading({
					title:"提交中..",
					mask:false
				});
				var that = this;
				// console.log(that.imgList.length); 
				// console.log(that.Goods_Image_Path1); 
				// console.log(defaultValue.imgurlHeader + that.Goods_Image_Path1); 
				// console.log(that.imgList[0].imgUrl); 
				if(this.type==0){
					that.Update_Add_GoodsMessage();
				}
				//新增
				else{
					that.Add();
				}
				// if( that.imgList.length==0 ){
				// 	if(that.imgList.length==0){ 
				// 		that.Goods_Image_Path1 = "";
				// 	}
					
				// 	//修改
					
				// 	return;
				// }
				// if(that.imgList.length!=0 && (defaultValue.imgurlHeader + that.Goods_Image_Path1) ==  that.imgList[0].imgUrl){					
				// 	//修改
				// 	if(this.type==0){
				// 		that.Update_Add_GoodsMessage();
				// 	}
				// 	//新增
				// 	else{
				// 		that.Add();
				// 	}
				// 	return;
				
			},
			UpLoadPic(GoodsID){
				var that = this;
				if(this.imgList.length!=0 && (defaultValue.imgurlHeader + this.Goods_Image_Path1) ==  this.imgList[0].imgUrl){
					this.$eventHub.$emit("isOptions",null);
					return;
				}
				
				if(this.uploadDef == that.imgList[0].imgUrl){
					return;
				}
				// console.log(that.imgList[0].imgUrl);
				uni.uploadFile({
					url: defaultValue.ConnentUrl+":"+defaultValue.ConnetPost+"/api/UpLoadPicture", //仅为示例，非真实的接口地址
					filePath: that.imgList[0].imgUrl+"",
					name: 'picture',
					formData: {
						"Database": "FastApp",
						"AddName": "商品图片",
						"GoodsID":GoodsID
					},
					success: (uploadFileRes) => {
						that.uploadDef = that.imgList[0].imgUrl;
						// console.log(uploadFileRes);
						// console.log(typeof uploadFileRes);
							uni.showToast({
								title:"图片提交成功",
								duration:1000
							})	
							that.$eventHub.$emit("isOptions",null);
					},fail(e){
						uni.hideLoading();
						uni.showToast({
							title:"提交失败，检查图片大小是否小于400K",
							duration:1000
						})
						that.$eventHub.$emit("isOptions",null);
					}
				});
			},
			//是否停止进货点击事件
			OpChange(e) {
				this.showOpmodle = false;
				this.NowSelectGoods.IsStopIn = e.detail.value
			},
			//是否停止进货点击事件
			OpChangeStop(e) {
				this.showOpmodle = false;
				console.log(this.NowSelectGoods.IsStopIn );
				this.NowSelectGoods.IsStopIn = e.detail.value
			},
			//是否停止销售点击
			OpChangeSalc(e) {
				this.showStopSale = false;
				this.NowSelectGoods.IsStopSale = e.detail.value
			},
			//是否停止使用点击
			OpChangeUser(e) {
				this.showUserModal = false;
				this.NowSelectGoods.IsStop = e.detail.value
			},
			//是否停止批号管理
			OpChangeInv(e) {
				this.showStopInv = false;
				this.NowSelectGoods.IsBatch = e.detail.value 
			},
			OpModal(e) {
				console.log(e);
				let type = e.currentTarget.dataset.type;
				if (type == 1) {
					this.showUserModal = true;
				} else if (type == 2) {
					this.showStopSale = true;
				} else if (type == 3) {
					this.showOpmodle = true;
				} else {
					this.showStopInv = true;
				}
			},
			hideModal(type) {
				//停止进货弹框 
				if (type == 1) {
					this.showUserModal = false;
				}
				if (type == 2) {
					this.showStopSale = false;
				}
				if (type == 3) {
					this.showOpmodle = false;
				}
				if (type == 4) {
					this.showStopInv = false;
				}
			},
			//选择供应商
			AddClientListen() {
				let isClient = 1
				uni.navigateTo({
					url: '../clientSelect/clientSelect?isClient=' + isClient + ""
				})
				var that = this;
				this.$eventHub.$on('clientListen', function(data) {
					that.SelectClientObj = JSON.parse(data);
					that.$eventHub.$off('clientListen');
				})
			},
			//清空
			Clear() {
				this.NowSelectGoods = {
					BarCode:"",
					GoodsCode:"",
					GoodsName:"",
					Spec:"",
					InPrice:0,
					SalePrice:0,
					Price1:0,
					Price2:0,
					Price3:0,
					VipPrice:0,
					PFPrice:0,
					Remark:"",
					IsStopIn:false,
					IsStopSale:false,
					IsStop:false,
					IsBatch:false,
					Days:0,
					Goods_Image_Path1:""
				};
				this.SelectClientObj = {
					ClientName: "",
					CreateID: ""
				};
				// let NowSelectGoods = JSON.parse(JSON.stringify(this.NowSelectGoods));
				// this.NowSelectGoods = NowSelectGoods;
				// this.NowSelectGoods.BarCode = "";
				// this.NowSelectGoods.GoodsCode = "";
				// this.NowSelectGoods.GoodsName = "";
				// this.NowSelectGoods.Spec = "";
				// this.NowSelectGoods.stockqty = "";
				// this.NowSelectGoods.InPrice = "0";
				// this.NowSelectGoods.SalePrice = "0";
				// this.NowSelectGoods.Price1 = "0";
				// this.NowSelectGoods.Price2 = "0";
				// this.NowSelectGoods.Price3 = "0";
				// this.NowSelectGoods.VipPrice = "0";
				// this.NowSelectGoods.InPrice = "0";
				// this.NowSelectGoods.SalePrice = "0";
				// this.NowSelectGoods.PFPrice = "0";
				// this.NowSelectGoods.Remark = "";
				// this.NowSelectGoods.Days = "";
				this.Spec = "";
				this.imgList = [];
				console.log(this.NowSelectGoods);
			},
			//调换到期初库存设置
			goInitial() {
				uni.navigateTo({
					url: '../info-initialInventory/info-initialInventory?GoodsID='+this.NowSelectGoods.GoodsID
				})
			},
			//是否停用
			IsStopSwitch(e) {
				let value = e.target.value;
				let that = this;
				this.$set(this.treatmentStatu, 'checked', value); // 将点击改变的状态赋给treatmentStatu.checked
				if (value && !this.havePromise) {
					uni.showModal({
						title: '提示',
						content: '是否停用',
						success: function(res) {
							if (res.confirm) {
								that.$emit('changePage', 1)
								console.log('用户点击确定')
							} else if (res.cancel) {
								that.$set(that.treatmentStatu, 'checked', false) // 手动修改switch的状态，视图会同步更新
								console.log('用户点击取消');
							}
						}
					});
				}
			},
			//是否批号管理
			PHIsStopSwitch(e) {
				let value = e.target.value;
				let that = this;
				this.$set(this.PHtreatmentStatu, 'checked', value); // 将点击改变的状态赋给treatmentStatu.checked
				if (value && !this.havePromise) {
					uni.showModal({
						title: '提示',
						content: '是否批号管理',
						success: function(res) {
							if (res.confirm) {
								that.$emit('changePage', 1)
								console.log('用户点击确定')
							} else if (res.cancel) {
								that.$set(that.PHtreatmentStatu, 'checked', false) // 手动修改switch的状态，视图会同步更新
								console.log('用户点击取消');
							}
						}
					});
				}
			},
			addMoreUnit(){
				uni.navigateTo({
					url:'../info-initialInventory/info-initialUnitName?GoodsID='+this.NowSelectGoods.GoodsID
				})
			},
			goBarCode(){
				uni.navigateTo({
					url:'../info-initialInventory/info-initialBarCode?GoodsID='+this.NowSelectGoods.GoodsID+"&GoodsName="+this.NowSelectGoods.GoodsName
				})
			},
			//停止进货
			CGIsStopSwitch(e) {
				let value = e.target.value;
				let that = this;
				this.$set(this.CGtreatmentStatu, 'checked', value); // 将点击改变的状态赋给treatmentStatu.checked
				if (value && !this.havePromise) {
					uni.showModal({
						title: '提示',
						content: '停止进货？',
						success: function(res) {
							if (res.confirm) {

								that.$emit('changePage', 1)
								this.NowSelectGoods.IsStopSale = value ? '1' : '0'
								console.log('用户点击确定')
							} else if (res.cancel) {
								that.$set(that.CGtreatmentStatu, 'checked', false) // 手动修改switch的状态，视图会同步更新
								console.log('用户点击取消');
								this.NowSelectGoods.IsStopSale = '0'
							}
						}
					});
				}
			},
			//停止销售
			XSIsStopSwitch(e) {
				let value = e.target.value;
				let that = this;
				this.$set(this.XStreatmentStatu, 'checked', value); // 将点击改变的状态赋给treatmentStatu.checked
				if (value && !this.havePromise) {
					uni.showModal({
						title: '提示',
						content: '停止进货？',
						success: function(res) {
							if (res.confirm) {
								that.$emit('changePage', 1)
								console.log('用户点击确定')
							} else if (res.cancel) {
								that.$set(that.XStreatmentStatu, 'checked', false) // 手动修改switch的状态，视图会同步更新
								console.log('用户点击取消');
							}
						}
					});
				}
			},
			//获取基本单位下拉款
			Get_GoodsUnitMessage() {
				let data = {
					Filter: ""
				}
				this.picker2 = [];
				var that = this;
				Api.Get_GoodsUnitMessage(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == "获取登录信息失败") {
							Api.showTip("登录超时");
						} else if (res.data.ErrorMsg != "") {
							Api.showTip(res.data.ErrorMsg);
						} else {
							let responseData = res.data.ResultMsg;
							that.UnitList = res.data.ResultMsg;
							// that.NowSelectGoods.UnitID = res.data.ResultMsg[0].UnitID;
							responseData.forEach((item, index) => {
								that.picker2.push(item.UnitName);
								if (item.UnitID == that.NowSelectGoods.UnitID) {
									that.index2 = index;
								}
							});
						}
					} else {

					}
				});
			},
			PickerChange2(e) {
				console.log(e)
				this.index2 = e.detail.value;
				console.log(this.StoreList);
				this.NowSelectGoods.UnitID = this.UnitList[this.index2].UnitID;
			},

			//获取商品类型下拉框
			GoodsTypeList() {
				let data = {
					Filter: ""
				}
				this.picker3 = [];
				var that = this;
				Api.GoodsTypeList(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == "获取登录信息失败") {
							Api.showTip("登录超时");
						} else if (res.data.ErrorMsg != "") {
							Api.showTip(res.data.ErrorMsg);
						} else {
							let responseData = res.data.ResultMsg;
							that.GoodTypeList = res.data.ResultMsg;
							// that.NowSelectGoods.GoodsTypeID = res.data.ResultMsg[0].GoodsTypeID;
							responseData.forEach((item, index) => {
								that.picker3.push(item.TypeName);
								if (item.GoodsTypeID == that.NowSelectGoods.GoodsTypeID) {
									that.index3 = index;
								}
							});
						}
					} else {

					}
				});
			},
			PickerChange3(e) {
				console.log(e)
				this.index3 = e.detail.value;
				this.NowSelectGoods.GoodsTypeID = this.GoodTypeList[this.index3].GoodsTypeID;
			},


			//获取供应商下拉框
			// Get_ClientMessage() {
			// 	let data = {
			// 		Filter: "IsClient<>1"
			// 	}
			// 	this.picker4 = [];
			// 	var that = this;
			// 	Api.Get_ClientMessage(data, function(res) {
			// 		if (res.state) {
			// 			if (res.data.ErrorMsg == "获取登录信息失败") {
			// 				Api.showTip("登录超时");
			// 			} else if (res.data.ErrorMsg != "") {
			// 				Api.showTip(res.data.ErrorMsg);
			// 			} else {
			// 				let responseData = res.data.ResultMsg;
			// 				that.StoreList = res.data.ResultMsg;
			// 				that.NowSelectGoods.ClientID = res.data.ResultMsg[0].ClientID;
			// 				responseData.forEach((item, index) => {
			// 					that.picker4.push(item.ClientName);
			// 					if (item.ClientName == that.NowSelectGoods.ClientName) {
			// 						that.index4 = index;
			// 					}
			// 				});
			// 			}
			// 		} else {

			// 		}
			// 	});
			// },
			PickerChange4(e) {
				console.log(e)
				this.index4 = e.detail.value;
			},
			//折扣改变事件
			changeZk(e) {
				console.log(e);
			},
			//获取当前选择的商品
			Update_Add_GoodsMessage() {
				let CreateID = uni.getStorageSync("UserCode");
				let Save_M_Data_Json = {
					GoodsID  :this.NowSelectGoods.GoodsID ,
					BarCode: this.NowSelectGoods.BarCode, //主条码
					GoodsCode: this.NowSelectGoods.GoodsCode, //商品编号
					GoodsName: this.NowSelectGoods.GoodsName, // 商品名称
					Spec: this.Spec, //商品规格      
					UnitID:  this.UnitList[this.index2].UnitID, //商品单位
					GoodsTypeID: this.GoodTypeList[this.index3].GoodsTypeID, //商品类型
					ClientID: this.SelectClientObj.ClientID, //主供应商
					Obj1: "", //     
					InPrice: this.NowSelectGoods.InPrice+"",
					SalePrice: this.NowSelectGoods.SalePrice+"",
					Price1: this.NowSelectGoods.Price1+"",
					Price2: this.NowSelectGoods.Price2+"",
					Price3: this.NowSelectGoods.Price3+"",
					VipPrice: this.NowSelectGoods.VipPrice+"",
					PFPrice: this.NowSelectGoods.PFPrice+"",
					Remark: this.NowSelectGoods.Remark,
					PyNo: "", //   拼音码
					IsStopIn: this.NowSelectGoods.IsStopIn+'' ,
					IsStopSale: this.NowSelectGoods.IsStopSale+'' ,
					IsStop: this.NowSelectGoods.IsStop +'' ,
					IsBatch: this.NowSelectGoods.IsBatch+'' ,
					Days: this.NowSelectGoods.Days+"",
					CreateID: CreateID,
					Spec: this.NowSelectGoods.Spec
				};
				if(this.imgList.length==0){
					Save_M_Data_Json.Goods_Image_Path1 = "0";
				}
				let data = {
					Save_M_Data_Json: JSON.stringify(Save_M_Data_Json)
				}
				var _this = this;
				Api.Update_Add_GoodsMessage(data, function(res) {
					uni.hideLoading();
					if (res.state) {
						if (res.data.TipsMsg == 'OK') {
							_this.Add_GoodsEarlyMessage(_this.NowSelectGoods.GoodsID);
							if(_this.imgList.length!=0){
								_this.UpLoadPic(_this.NowSelectGoods.GoodsID);
							}else{
								_this.$eventHub.$emit("isOptions",null);
							}
							
							// _this.UpLoadPicture();
							Api.showTip("修改成功");
							
							
							// uni.navigateBack({
							// 	delta:1
							// })
						} else if (res.data.ErrorMsg != "") {
							Api.showTip(res.data.ErrorMsg);
						} else {

						}
					} else {
						Api.showTip("服务器开小差了");
					}
				})
			},
		    //
		    Add() {
		    	let CreateID = uni.getStorageSync("UserCode");
		        if(this.SelectClientObj.ClientID==""){
					Api.isShowTip("请先选择供应商!");
					return;
				}
				console.log(this.Spec);
		    	let Save_M_Data_Json = {
		    		BarCode: this.NowSelectGoods.BarCode, //主条码
		    		GoodsCode: this.NowSelectGoods.GoodsCode, //商品编号
		    		GoodsName: this.NowSelectGoods.GoodsName, // 商品名称
		    		Spec: this.Spec, //商品规格      
		    		UnitID: this.UnitList[this.index2].UnitID, //商品单位
		    		GoodsTypeID: this.GoodTypeList[this.index3].GoodsTypeID, //商品类型
		    		ClientID: this.SelectClientObj.ClientID, //主供应商
		    		Obj1: "", //     
		    		InPrice: this.NowSelectGoods.InPrice+"",
		    		SalePrice: this.NowSelectGoods.SalePrice +"",
		    		Price1: this.NowSelectGoods.Price1+"",
		    		Price2: this.NowSelectGoods.Price2+"",
		    		Price3: this.NowSelectGoods.Price3+"",
		    		VipPrice: this.NowSelectGoods.VipPrice+"",
		    		PFPrice: this.NowSelectGoods.PFPrice+"",
		    		Remark: this.NowSelectGoods.Remark,
		    		PyNo: "", //   拼音码
		    		IsStopIn: this.NowSelectGoods.IsStopIn+'' ,
		    		IsStopSale: this.NowSelectGoods.IsStopSale+'' ,
		    		IsStop: this.NowSelectGoods.IsStop+'' ,
		    		IsBatch: this.NowSelectGoods.IsBatch+'' ,
		    		Days: this.NowSelectGoods.Days+"",
		    		CreateID: CreateID
		    		
		    
		    	};
				// console.log(Save_M_Data_Json);
				// return;
		    	let data = {
		    		Save_M_Data_Json: JSON.stringify(Save_M_Data_Json)
		    	}
		    	var _this = this;
		    	Api.Add_GoodsMessage(data, function(res) {
		    		uni.hideLoading();
		    		if (res.state) {
		    			if (res.data.TipsMsg == 'OK') {
		    				_this.Add_GoodsEarlyMessage(res.data.ResultMsg.GoodsID);
							_this.UpLoadPic(res.data.ResultMsg.GoodsID);
		    				// _this.UpLoadPicture();
		    				Api.showTip("新增成功");
							_this.Clear();
							// _this.$eventHub.$emit("isOptions",null);
		    				// uni.navigateTo({
		    				// 	url: './info-GoodsMessage01'
		    				// })
		    
		    			} else if (res.data.ErrorMsg != "") {
		    				Api.showTip(res.data.ErrorMsg);
		    			} else {
		    
		    			}
		    		} else {
		    			Api.showTip("服务器开小差了");
		    		}
		    	})
		    },
			//新增期初库存
			Add_GoodsEarlyMessage(GoodsID) {
				let qckc = uni.getStorageSync("qckc","");
				if (typeof qckc == 'string') {
					try {
						let qckcObj = JSON.parse(qckc);
						var _this = this;
						let CreateID = uni.getStorageSync("UserCode");
						let Save_D_Data_Json = [];
						qckcObj.forEach((item,index)=>{
							 var items = {
								 StoreID: item.StoreID,
								 Qty: item.Qty + "",
								 Price: item.Price + "",
								 Total: (item.Qty * item.Price) + "",
								 CreateID: CreateID,
								 BatchNo: item.BatchNo
							 }
							 Save_D_Data_Json.push(items);
						});
						let data = {
							GoodsID:GoodsID,
							Save_D_Data_Json: JSON.stringify(Save_D_Data_Json)
						}
						Api.Add_GoodsEarlyMessage(data, function(res) {
							uni.setStorageSync("qckc","");
							if (res.state) {
								if (res.data.TipsMsg == 'OK') {
									 // uni.setStorageSync("qckc","");
									// Api.showTip("新增成功");
								} else if (res.data.ErrorMsg != "") {
									Api.showTip(res.data.ErrorMsg);
								} else {
									console.log(res);
								}
							} else {
								Api.showTip("服务器开小差了");
							}
						})
					} catch (e) {
						console.log(e);
					}
				}

			},
			//计算折扣后商品价格
			computPrice(item) {
				item.PFPrice = item.PFPrice * item.Qty * (item.Discount / 100) * (1 + item.Tax / 100);
				return item;
			},
			//选择图片
			ChooseImage() {
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['camera'], //从相册选择
					success: (res) => {
						this.imgList = res.tempFilePaths
						// if (this.imgList.length != 0) {
						// 	this.imgList = this.imgList.concat(res.tempFilePaths)
						// } else {
						// 
						// }
					}
				});
			},
			ViewImage(e) {
				uni.previewImage({
					urls: this.imgList,
					current: e.currentTarget.dataset.url
				});
			},
			DelImg(e) {
				uni.showModal({
					title: '商品图片',
					content: '确定要删除吗？',
					cancelText: '取消',
					confirmText: '确定',
					success: res => {
						if (res.confirm) {
							this.imgList.splice(e.currentTarget.dataset.index, 1)
						}
					}
				})
			},
		}
	}
</script>

<style >
	/* // @import url("./info-GoodsMessage.scss"); */

	.uni-switch-input.uni-switch-input-checked {
		border-color: #007aff !important;
		background-color: #007aff !important;
	}

	.clientSearchItem02 {
		width: 100%;
		height: 50px;
		display: flex;
		/* top: 0px; */
		box-sizing: border-box;
		padding: 2px 0px 0px 2px;
		position: fixed;
		background: #FFFFFF;
		z-index: 9999;
	}
	.clientSearchItem02 .searchBt {
		flex: 1;
		height: 35px;
		line-height: 35px;
		border-radius: 5px;
		border: 1px solid #ccc;
		padding-left: 10px;
		font-size: 14px;
		background: #0081FF;
		color: #FFFFFF;
	}

	.detail-box {
		padding-top: 50px;
	}

	.cu-form-group {
		padding: 1px 10px !important;
		height: 40px;
		line-height: 40px;
		min-height: 40px;
	}

	.cu-form-group02 {
		padding: 1px 10px !important;
		height: 90px;
		line-height: 40px;
		min-height: 40px;
	}
	
	
	.cu-form-group uni-picker .picker{
		height: 40px;
		line-height: 40px;
	}
	
	.cu-form-group .title{
		height: 40px;
		line-height: 40px;
	}
</style>
